<template>
  <div class="app-container">
      <el-form ref="form" :model="form" :rules="rules" label-width="200px" style="width:50%">
        <el-row>
          <el-col :span="6">
            <el-form-item />
          </el-col>
          <el-col :span="18">
            <el-form-item label="提现功能" prop="status">
              <el-switch v-model="form.status"  active-color="#13ce66" inactive-color="#ff4949" active-value="1" inactive-value="0"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="宠爱值提现设置" />
          </el-col>
          <el-col :span="18">
            <el-form-item label="申请提现日期" prop="applyDailyType">
              <el-radio-group  v-model="form.applyDailyType" placeholder="请选择提现渠道">
                <el-radio :label="1">每天</el-radio>
                <el-radio :label="2">每周一</el-radio>
                <el-radio :label="3">每月1日</el-radio>
                <el-radio :label="4">自定义</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item v-if="form.applyDailyType === 4" label="提现日期" prop="applyDaily">
              <el-input v-model="form.applyDaily" placeholder="请输入申请提现日期" />
            </el-form-item>
            <el-form-item label="满多少宠爱值可提现" prop="fullPet">
              <el-input-number v-model="form.fullPet" placeholder="宠爱值" />
            </el-form-item>
            <el-form-item label="宠爱值提现费率" prop="ratePet">
              <el-input-number v-model="form.ratePet" placeholder="费率" />
            </el-form-item>
            <el-form-item label="提现宠爱值需为" prop="cardinalPet">
              <el-input-number v-model="form.cardinalPet" placeholder="" />整数倍
            </el-form-item>
            <el-form-item label="日提现次数限制" prop="dailyBoutPet">
              <el-input-number v-model="form.dailyBoutPet" placeholder="不限" />
            </el-form-item>
            <el-form-item label="日提现金额限制" prop="dailyMoney">
              <el-input-number v-model="form.dailyMoney" placeholder="不限" />
            </el-form-item>
          </el-col>
        </el-row>
       
        <el-row>
          <el-col :span="6">
            <el-form-item label="订单收入提现设置" />
          </el-col>
          <el-col :span="18">
            <el-form-item label="满多少收入可提现" prop="fullOrder">
              <el-input-number v-model="form.fullOrder" placeholder="请输入满多少收入可提现" />
            </el-form-item>
            <el-form-item label="收入提现费率" prop="orderRate">
              <el-input-number v-model="form.orderRate" placeholder="请输入收入提现费率" />
            </el-form-item>
            <el-form-item label="提现收入需为(基数)" prop="cardinalOrder">
              <el-input-number v-model="form.cardinalOrder" placeholder="请输入提现收入需为(基数)" />
            </el-form-item>
            <el-form-item label="日提现次数限制" prop="dailyBoutOrder">
              <el-input-number v-model="form.dailyBoutOrder" placeholder="请输入日提现次数限制" />
            </el-form-item>
            <el-form-item label="日提现金额限制" prop="dailyMoneyOrder">
              <el-input-number v-model="form.dailyMoneyOrder" placeholder="请输入日提现金额限制" />
            </el-form-item>
            <el-form-item label="收入提现渠道" prop="channel">
              <el-select v-model="form.channel" placeholder="请选择提现渠道">
                <el-option v-for="dict in channelOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
              </el-select>
            </el-form-item>

            <el-form-item >
                <el-button type="primary" @click="submitForm">提交生效</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        
      </el-form>
  </div>
</template>

<script>
import { listExchangeMoney, getExchangeMoney, delExchangeMoney, addExchangeMoney, updateExchangeMoney, exportExchangeMoney } from "@/api/system/exchangeMoney";

export default {
  name: "ExchangeMoney",
  data() {
    return {
      channelOptions:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        applyDailyType: [
          { required: true, message: "申请提现日期不能为空", trigger: "blur" }
        ],
        applyDaily: [
          { required: true, message: "申请提现日期不能为空", trigger: "blur" }
        ],
        fullPet: [
          { required: true, message: "满多少宠爱值可提现不能为空", trigger: "blur" }
        ],
        ratePet: [
          { required: true, message: "宠爱值提现费率不能为空", trigger: "blur" }
        ],
        cardinalPet: [
          { required: true, message: "提现宠爱值需为不能为空", trigger: "blur" }
        ],
        fullOrder: [
          { required: true, message: "满多少收入可提现不能为空", trigger: "blur" }
        ],
        orderRate: [
          { required: true, message: "收入提现费率不能为空", trigger: "blur" }
        ],
        cardinalOrder: [
          { required: true, message: "提现收入需为(基数)不能为空", trigger: "blur" }
        ],
        channel: [
          { required: true, message: "收入提现渠道不能为空", trigger: "blur" }
        ],
      },
      id:1
    };
  },
  created() {
    this.$nextTick(()=>{
      this.getDicts("withdraw_channel").then(response => {
        this.channelOptions = response.data;
      });
    })
    
    getExchangeMoney(this.id).then(response => {
      this.form = response.data;
    });
  },
  methods: {
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateExchangeMoney(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addExchangeMoney(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    }
  }
};
</script>